package edu.ssm.campusAssistant.bo.rsp;

import com.github.pagehelper.Page;

import java.util.Collection;
import java.util.List;

/**
 * 标题:分页返回参数
 * 描述:
 *
 * @autho LXF
 * @date 2019/4/8 18:14
 */
public class RspPageBO<T> extends RspBO {
    private static final long serialVersionUID = -2239195625095428743L;

    /**
     * 数据
     */
    private List<T> list;

    /**
     * 记录总数
     */
    private int total;

    /**
     * 总页数
     */
    private int pages;

    /**
     * 当前页
     */
    private int pageNo;
    /**
     * 当前数量
     */
    private int size;

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public int getPages() {
        return pages;
    }

    public void setPages(int pages) {
        this.pages = pages;
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public int getSize() {
        return size;
    }

    public void setSize(int size) {
        this.size = size;
    }

    @Override
    public String toString() {
        return "RspPageBO{" +
                "list=" + list +
                ", total=" + total +
                ", pages=" + pages +
                ", pageNo=" + pageNo +
                ", size=" + size +
                '}';
    }

    public RspPageBO(List list) {
        if (list instanceof Page) {
            Page page = (Page) list;
            this.total = (int) page.getTotal();
            this.pages = page.getPages();
            this.size = page.size();
            this.pageNo = page.getPageNum();
        } else if (list instanceof Collection) {
            this.pageNo = 1;
            this.pages = list.size() > 0 ? 1 : 0;
            this.size = list.size();
            this.total = list.size();
        }

    }


}
